﻿using MediatR;
using W.Purchase.API.Application.Command.PayableCommand;
using W.Purchase.Repository.Impl;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.PayableCommandHandler
{
    public class PayableRangeDelCommandHandler:IRequestHandler<PayableRangeDelCommand,int>
    {
        private readonly IPayableRepository _ipayableRepository;
        public PayableRangeDelCommandHandler(IPayableRepository payableRepository)
        {
            _ipayableRepository = payableRepository;
        }

        public async Task<int> Handle(PayableRangeDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _ipayableRepository.GetAllAsaync();
            var plist = list.Where(c => request.Ids.Contains(c.PayableId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _ipayableRepository.UpdateRangeAsync(plist);
            return n;
        }
    }
}
